﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace hse_2013_test_dima_sasha
{
    public class Question
    {
        private string question;
        private Answers[] AllAnswers = new Answers[10];

        public Question()
        {
        }

        public Question(string qS,Answers[] AllA )
        {
            question=qS;
            AllAnswers=AllA;
        }

        public Answers[] GetAnswers()
        {
            return AllAnswers;
        }
        public Answers[] SetAnswers(Answers[] answers)
        {
           return AllAnswers=answers;
        }
        public string GetVopros()
        {
            return question;
        }
        public int[] Randomizer(int count)
        {
            return Randomize(count);
        }
        private int[] Randomize(int length)
        {
            Random random = new Random();
            int[] massiv = Enumerable.Range(0, length).OrderBy(n => random.Next()).ToArray();
            return massiv;
        }
        public List<Question> SortQuestionsAndAnswers(int input)
        {
            var NewQuestions = new List<Question>();
            int[] variant = Randomize(input);
            for (int i = 0; i < variant.Length; i++)
            {
                NewQuestions.Add(Data.ListOfQuestions.ElementAt(variant[i]));
            }
            foreach (Question Q in NewQuestions)
            {
                var SortedAnswers = new Answers[Q.GetAnswers().Count()];
                variant=Randomize(Q.GetAnswers().Count());
                for (int i = 0; i < Q.GetAnswers().Count(); i++)
                {
                    SortedAnswers[i] = Q.GetAnswers()[variant[i]];
                }
                Q.SetAnswers(SortedAnswers);
            }
            return NewQuestions;
        }

    }
}
